package com.bit.cfdi.web.ws;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;

import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.bit.cfdi.web.dao.UsuarioDAO;
import com.bit.cfdi.web.domain.Usuario;

@Component
@Path("/login")
public class LoginWebService {
	
	private Logger log = LogManager.getLogger(this.getClass().getName());
	
	@Autowired
	private UsuarioDAO usuarioDAO;

	@GET @Path("/do")
	@Produces(MediaType.TEXT_PLAIN)
	public String loginGet(
			@QueryParam("email") final String email,
			@QueryParam("password") final String password) {
		
		Usuario usuario = usuarioDAO.getByEmailAndPassword(email, password);
		if(usuario == null) {
			log.warn("usuario doesn't exist");
			return "";
		}
		return "user_verified";
	}
}
